(function ({form, table, layer, laydate, SelectDatas,vappraisalsid,appraisals, scoreinfoTableIns,scoreinfos,url, contentType, ok, AjaxFn, tablebtn, updataOpen, optionfor,startAndForbid}) {

    /* select， radio 渲染*/
    SelectDatas = ((obj)=>(obj = AjaxFn(url + "appraisalSelectDatas", "", obj), {vappraisalsflg = '', vassessflg = ''} = obj, $("select[name=vassessflg]").html(optionfor(vassessflg, ``,"select")), $(".radioAppraisalsflg").html(optionfor(vappraisalsflg, "","radio"))))({}),

    /*考题/答案数据加载*/
    appraisals=((obj)=>(obj=AjaxFn(url+"appraisalAndScoreinfos",JSON.stringify({vappraisalsid}),obj), {appraisal='',scoreinfo=''}=obj,scoreinfos=scoreinfo,appraisals=appraisal))({}),
    /*考题赋值*/
    (()=>(form.val('appraisalAddForm',appraisals),form.render()))(),

    form.verify({
        costomnum :function(value){
            if (!/^[+-]{0,1}(\d+)$/.test(value)) return '不能输入小数';
        }
    }),

    /*答案分值 表格渲染*/
    scoreinfoTableIns =  table.render({
        elem: '#scoreinfoTable',
        id:"scoreinfoTable",
        limit:6,
        page: {first: '首页', last: '尾页', prev: '上一页', next: '下一页', layout: ['count', 'prev', 'page', 'next'], groups: 5, theme: '#1e9fff', limits: [10, 20, 30, 40, 50],},
        cols: [
            [
                {title: '操作', fixed: "left", unresize: true, align: "center", width:80, minWidth: 80,
                    templet: function ({newscoreinfo='',vdelflg, del = '',start='',forbid=''}) {
                        newscoreinfo!=''?
                            del = tablebtn({"event": "del", "btnclass": "layui-btn layui-btn-xs layui-btn-danger", "icon": '&#xe640;', "text": '删除', "disabled": false}):
                            forbid = vdelflg == '1' ?
                                tablebtn({
                                    "event": "start",
                                    "btnclass": "layui-btn layui-btn-xs layui-btn-normal",
                                    "icon": '&#xe683;',
                                    "text": '启用',
                                    "disabled": false
                                }) :
                                tablebtn({
                                    "event": "forbid",
                                    "btnclass": "layui-btn layui-btn-xs layui-btn-warm",
                                    "icon": '&#xe673;',
                                    "text": '禁用',
                                    "disabled": false
                                });
                        return '<div>' + del + forbid + '</div>';
                    }
                },
                {field: 'vdelflgname', title: '状态', unresize: true, align: "center",width:80,minWidth: 65},
                {field: 'vstandard', title: '标准（答案）',edit: 'vstandard', unresize: true, align: "center", minWidth: 200},
                {field: 'iscore', title: '分值', edit: 'iscore',unresize: true, align: "center", width:100,minWidth: 100},
            ]
        ],
        data: scoreinfos
    })

    /*监听 答案/分值 添加*/
    form.on('submit(scoreinfoAdd)',function ({field}) {scoreinfos.length==0?(()=>(field.vno=1,field.newscoreinfo="new",field.vdelflg=0,field.vdelflgname="有效",scoreinfos.splice(0,0,field)))(): scoreinfos.findIndex(v=>v.vstandard==field.vstandard)==-1?(()=>(field.vno=scoreinfos.length+1,field.newscoreinfo="new",field.vdelflg=0,field.vdelflgname="有效",scoreinfos.splice(0,0,field)))():layer.msg('标准（答案）已存在', {icon: 7}), table.reload("scoreinfoTable",{data:scoreinfos}), form.val('scoreinfoForm',{vstandard:'', iscore:""});return false;})

    /*监听 修改*/
    form.on('submit(appraisaUpdata)',function ({field,res=''}) {
        field.vcontent = field.vcontent.trim()
        scoreinfos.length==0?($("#scoreinfoAdd").click()):(
            scoreinfoArr = scoreinfos.filter(v => (v.newscoreinfo == "new")),
            res = AjaxFn(url+"appraisaUpdata", JSON.stringify({field,scoreinfoArr}), {}),
                {code,msg}=res,code==200?(()=>(layer.alert(msg,{icon:1,skin: 'updata-alert-class'},()=>(parent.layer.closeAll()))))():layer.msg(msg,{icon:5}));
        return false;
    })

    /*监听 删除 启用 禁用*/
    table.on('tool(scoreinfoTable)',(obj)=>(
        obj.event=="del"?(
            scoreinfos.splice(scoreinfos.findIndex(v=>v.vstandard==obj.data.vstandard),1),obj.del()
            ):
            obj.event=="start"?((d)=>(
                    d.startAndForbid="启用",
                    d.masg="确定启用该答案吗？",
                    d.btns=['取消','启用'],
                    d.param=obj.data,d.tableIns=table,
                    d.url=url+"scoreinfoStartAndForbid",
                    d.scoreinfos=scoreinfos,
                    startAndForbid(d)
                )
            )({}):
                obj.event=="forbid"?(
                    (d)=>(
                        d.startAndForbid="禁用",
                            d.masg="确定禁用该答案吗？",
                            d.btns=['取消','禁用'],
                            d.param=obj.data,
                            d.tableIns=table,
                            d.url=url+"scoreinfoStartAndForbid",
                            d.scoreinfos=scoreinfos,
                            startAndForbid(d)
                    )
                )({}):''))

    /*监听单元格编辑 {value,data,field,obj={},b=true}*/
    table.on('edit(scoreinfoTable)', function ({value,data,field,obj={},b=true}) {
        field =='iscore'?!/^[+-]{0,1}(\d+)$/.test(value)?(layer.msg("不能输入小数",{icon:5}),b=false,$(this).val($(this).prev().text())):b=true:'',
        b?(
            data.vstandard=data.vstandard.trim(),data.iscore=data.iscore.trim(),
            obj = AjaxFn(url+"standardAndIscoreUpdata", JSON.stringify(data), obj),
            obj.code==200?icon=1:icon=5, layer.msg(obj.msg,{icon:icon})
        ):''
        }
    );

})({
    form: layui.form,
    table: layui.table,
    layer: layui.layer,
    laydate: layui.laydate,
    SelectDatas: {},
    scoreinfoTableIns:'',
    scoreinfos:[],
    appraisals:{},
    vappraisalsid:$("input[name=vappraisalsid]").val(),
    url: "/evaluation/appraisal/",
    contentType: 'application/json;charset=utf-8',
    ok: function (msg, icon) {
        layui.layer.confirm(msg, {
            id: "ok",
            icon: icon,
            anim: 4,
            title: '提示',
            btn: ['确定'],
            closeBtn: false,
            success: function (layero) {
                var btn = layero[0].getElementsByClassName('layui-layer-btn')[0].getElementsByTagName('A')[0];
                btn.href = 'javascript:void(0)';
                btn.focus();
            },
            yes: function (index, layero) {
                layer.close(index); //再执行关闭
            },
            end: function () {
                var index2 = parent.layer.getFrameIndex(window.name);
                parent.layer.closeAll();
            }
        });
    },
    AjaxFn: function (url, data, resource) {
        $.ajax({
            url,
            contentType: 'application/json;charset=utf-8',
            type: 'post',
            async: false,
            data,
            success: function (res) {
                let {msg='',code=''} =res;
                msg=='' && code==''? top.location.reload() : "";
                resource = res;
            }
        });
        return resource;
    },
    tablebtn: function ({event = "", btnclass = "layui-btn btncolor ", icon = "", text = "", disabled = false, btn = ""}) {
        disabled ? disabled = "disabled" : disabled = '';
        btn = `<button type="button" ${disabled} class="${btnclass}" lay-event="${event}"><i class="layui-icon">${icon}</i>${text}</button>`
        return btn;
    },
    updataOpen: function ({url, skin, title, tableIns, btns = ['取消', '修改']}) {
        layer.open({
                anim: 4, type: 2, skin: skin, resize: false,
                title: [title, 'font-size:18px; background-color:#e7eaec;'],
                area: ['aotu'],
                btn: btns,
                content: url,
                btn2: function (index, layero) {
                    var body = layer.getChildFrame('body', index);
                    body.find('#submit').click();
                    return false;
                },
                end: function () {
                    tableIns.reload();
                }
            }
        ), $(`.${skin} iframe`).css('height', '100%'),
            $(".layui-layer-btn").css({
                "padding-top": "0px",
                "padding-bottom": "3px",
                "background-color": "rgb(231, 234, 236)"
            });
    },
    optionfor: (vappraisalsflg, op,rORs) => {
        rORs=="select"?
            (()=>(vappraisalsflg != '' ? $.each(vappraisalsflg, (i, item) => op += `<option value="${item.scode}">${item.vname}</option>`) : op = ""))():
            rORs=="radio"? (()=>(
                    vappraisalsflg != '' ? $.each(vappraisalsflg, (i, item) =>(
                        item.scode==0?rORs = "checked":rORs="",
                            op += `<input type="radio" name="vappraisalsflg" value="${item.scode}" title="${item.vname}">`)) : op = ""
                )
            )():'';
        return op;
    },
    startAndForbid: function ({startAndForbid, masg, btns, param, tableIns, url,scoreinfos}) {
        layui.layer.confirm(masg, {
            id: "startAndForbid",
            icon: 3, anim: 4, title: '提示',
            btn: btns,
            success: function (layero) {
                let btn = layero[0].getElementsByClassName('layui-layer-btn')[0].getElementsByTagName('A')[0];
                btn.href = 'javascript:void(0)', btn.focus();
            },
            btn2: function (index, layero) {
                let {vdelflg, vappraisalsid,vno} = param;
                param.vdelflg == "1" ? vdelflg = "0" : param.vdelflg == "0" ? vdelflg = "1" : "",
                    $.ajax({
                        url,
                        contentType: 'application/json;charset=utf-8',
                        type: 'post',
                        async: false,
                        data: JSON.stringify({vdelflg, vappraisalsid,vno,startAndForbid}),
                        success: function (res) {
                            let {msg='',code='',data=''} =res;
                            msg=='' && code==''? top.location.reload() : "";
                            code == 200 ? (()=>(icon = 1,
                                scoreinfos[scoreinfos.findIndex(v=>v.vno==data.vno)].vdelflg=data.vdelflg,
                                scoreinfos[scoreinfos.findIndex(v=>v.vno==data.vno)].vdelflgname=data.vdelflgname
                            ))():icon = 5;
                            layer.msg(msg, {icon: icon});
                        }
                    })
            },
            end: function () {
                tableIns.reload("scoreinfoTable",{data:scoreinfos});
            }
        });
    },
})